//
//  GoodsTypeTableViewHeaderFooterView.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/20.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "GoodsTypeTableViewHeaderFooterView.h"

@interface GoodsTypeTableViewHeaderFooterView (){
    GLGWButton * selectAllTypeBut;
    GLGWLabel * typeTitleLabel;
}

@end

@implementation GoodsTypeTableViewHeaderFooterView

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        GLGWView * topGaryView = [[GLGWView alloc] initWithInSuperView:self.contentView];
        topGaryView.backgroundColor = [UIColor colorWithHexString:@"#F2F2F2"];
        [topGaryView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self.contentView);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(10)));
        }];
        //下面才是重点
        selectAllTypeBut = [[GLGWButton alloc] initInSuperView:self.contentView];
        [selectAllTypeBut mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(kWidthProportion_In_iPhoneTriploid(5));
            make.top.equalTo(topGaryView.mas_bottom).offset(0);
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(40)));
            make.width.equalTo(@(kWidthProportion_In_iPhoneTriploid(40)));
        }];
        selectAllTypeBut.image_Name = @"icon_weixuanzhe";
        [selectAllTypeBut setImage:[UIImage imageNamed:@"icon_xuanzhe_zhaopian"] forState:UIControlStateSelected];
        [selectAllTypeBut addTarget:self action:@selector(headerSelectBut:) forControlEvents:UIControlEventTouchUpInside];
        typeTitleLabel = [[GLGWLabel alloc] initWithFont:SYSTEMFONT(16) theColor:kColor_Rule_Yellow inSuperView:self.contentView];
        [typeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self->selectAllTypeBut.mas_right).offset(kWidthProportion_In_iPhoneTriploid(10));
            make.top.equalTo(topGaryView.mas_bottom).offset(kHeightProportion_In_iPhoneTriploid(9));
            make.height.equalTo(@(kHeightProportion_In_iPhoneTriploid(22)));
        }];
        //
        GLGWView * lineView = [[GLGWView alloc] initWithInSuperView:self];
        lineView.backgroundColor = [UIColor colorWithHexString:@"#EAEAEA"];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.left.bottom.equalTo(self);
            make.height.equalTo(@1);
        }];
    }
    return self;
}


-(void)setH_model:(ShopCarModel_Header *)h_model{
    _h_model = h_model;
    CGRect rectr = CGRectZero;
    if ([_h_model.titleImageStr isEqualToString:@"icon_jisujiaoyi"]) {
        rectr = CGRectMake(0, -4.5, kWidthProportion_In_iPhoneTriploid(20), kHeightProportion_In_iPhoneTriploid(20));
        typeTitleLabel.textColor = kColor_Rule_Yellow;
    }else if ([_h_model.titleImageStr isEqualToString:@"icon_changqiqiugou"]){
        rectr = CGRectMake(0, -5, kWidthProportion_In_iPhoneTriploid(18), kHeightProportion_In_iPhoneTriploid(20));
        typeTitleLabel.textColor = kColor_Rule_Yellow;
    }else{
        rectr = CGRectMake(0, -1.5, kWidthProportion_In_iPhoneTriploid(20), kHeightProportion_In_iPhoneTriploid(15));
        typeTitleLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    }
    typeTitleLabel.attributedText = [GLGWLabel addImageName:_h_model.titleImageStr theImageFram:rectr theTextString:_h_model.titleStr atImageIndex:0];
    selectAllTypeBut.selected = _h_model.sectionBool;
}

-(void)headerSelectBut:(GLGWButton *)sender{
    if (self.Block_HeaderAllSelect) {
        self.Block_HeaderAllSelect(sender);
    }
}

@end
